<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 							
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
   
	$(document).ready(function(){
	
			
				//高级搜索需要的js
				buttonStatus=1;
				$("#flip").click(function(){
					if(buttonStatus==1){
						$("#panel").slideToggle("slow");
						$("#flip").toggleClass("btnStatus2");
						buttonStatus=1;
					}
					else{
						$("#panel").slideUp("slow");
						$("#flip").toggleClass("btnStatus2");
					}
			 });
				 //高级搜索结束
	
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/autoForms/item!queryGwmItemList.action',
						datatype: "json",
						height: "400",
						width: '1000', 
						//autowidth:true,
						colNames:['主键','检测项目','检测单位','检测单位代码','检测地点','检测部门','检测类别','检测费用','检测单位ID'],
						colModel:[
						    {name:'ID',index:'ID', width:60, key:true, sorttype:"int",hidden:true,hidedlg:true}, 
						    {name:'T_ITEMNAME',index:'T_ITEMNAME', width:150},
						    {name:'T_JIANCEDANWEI_NAME',index:'T_JIANCEDANWEI_NAME', width:180},
						    {name:'T_GONGSIDAIMA',index:'T_GONGSIDAIMA', width:100},
						    {name:'T_JIANCEDIDIAN',index:'T_JIANCEDIDIAN', width:100},
						    {name:'T_JIANCEBUMEN',index:'T_JIANCEBUMEN', width:130},
						    {name:'T_JIACELEIBIE',index:'T_JIACELEIBIE', width:100},
						    {name:'T_JIANCEMONEY',index:'T_JIANCEMONEY', width:100,hidden:true},
						    {name:'T_JIANCEDANWEI',index:'T_JIANCEDANWEI', width:100,hidden:true} 
						  ],
						shrinkToFit:false,
						sortname:'NEWID',
						sortorder:'desc',
						viewrecords:true,
						multiselect: true, // 是否显示复选框
						multiboxonly : true, 
						//gridview: true,  //提升速度
						rownumbers: true,//显示行号
						rownumWidth: 30, //行号的宽度
						rowNum:50,
						rowList:[15,20,50,200,500],
						toolbar: [false,"top"],
						jsonReader: {
							root:"rows",		// 数据行（默认为：rows）
							page: "page",  	// 当前页
							total: "total",  // 总页数
							records: "records",  // 总记录数
							repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
						},
						prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
						pager:"#gridPager",
						subGrid: true,
					    subGridRowExpanded: function(subgrid_id, row_id) {
					    
					       
						   var rowData = $("#gridTable").getRowData(row_id);
					       var subgrid_table_id = subgrid_id+"_t";
					  
					       jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
					    
					       jQuery("#"+subgrid_table_id).jqGrid({
					    	   url:common_basePath+'autoForms/item!queryItemBiaozhunByItemId.action?itemId='+row_id+'&itemName='+encodeURIComponent(encodeURIComponent(rowData.T_ITEMNAME))+'&danwei='+rowData.T_JIANCEDANWEI+'&temp='+Math.round(Math.random()*10000),
					    	    datatype: "json", 
								colNames:['ID','检测标准','检测单位','检测费用'],
								colModel:[
									{name:'ID',index:'ID', width:100,key:true,hidden:true,hidedlg:true} ,
									{name:'T_JIANCEBIAOZHUN',index:'T_JIANCEBIAOZHUN', width:450},
									{name:'T_JIANCEDANWEI_NAME',index:'T_JIANCEDANWEI_NAME', width:100},
									{name:'T_JIANCEMONEY',index:'T_JIANCEMONEY', width:80}
									], 
								jsonReader: {
									root:"rows",		// 数据行（默认为：rows）
									page: "page",  	// 当前页
									total: "total",  // 总页数
									records: "records",  // 总记录数
									repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
								},  
								shrinkToFit:false,
							    height:"auto", 
							    multiselect: true, 
							    width:800,
								rowNum:500,
								sortname:'NEWID',
								sortorder:'asc'
					       });
					     },
						caption: "检测项目列表"	
			});
			  
	}); 
	
	    //执行大小
	   function doResize() { 
		    var ss = getPageSize(); 
		
		    $("#gridTable").jqGrid('setGridHeight', ss.WinH-245);
		    $("#gridTable").jqGrid('setGridWidth', ss.WinW-30); 
		} 
		
		//查询
		function gridSearch(){
			var itemname = $.trim(jQuery("#T_ITEMNAME").val());
            var jiancedanwei = $.trim(jQuery("#T_JIANCEDANWEI").val()); 
            var didian = $.trim(jQuery("#T_JIANCEDIDIAN").val());
            var bumen = $.trim(jQuery("#T_JIANCEBUMEN").val());
            var leibie = $.trim(jQuery("#T_JIACELEIBIE").val());
            
            
            var params = {  
                        "T_ITEMNAME" : encodeURIComponent(itemname),                           
                        "T_JIANCEDANWEI" : encodeURIComponent(jiancedanwei),
                        "T_JIANCEDIDIAN" : encodeURIComponent(didian),
                        "T_JIANCEBUMEN":encodeURIComponent(bumen),
                        "T_JIACELEIBIE":encodeURIComponent(leibie)
                         };
            var postData = $("#gridTable").jqGrid("getGridParam", "postData");
            $.extend(postData, params);
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/autoForms/item!queryGwmItemList.action'
			}).trigger("reloadGrid", [{page:1}]);
        } 
       
		//刷新
		function refreshIt(){
			//resetSearch();
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/autoForms/item!queryGwmItemList.action'
			}).trigger("reloadGrid", [{page:1}]);
		    
		}
		function reload(){
			refreshIt();
		}
		//清空
		function reset(){
			jQuery("#T_ITEMNAME").val("");
			jQuery("#T_JIANCEDANWEI").val("");
			jQuery("#T_JIANCEDIDIAN").val("");
			jQuery("#T_JIANCEBUMEN").val("");	
			jQuery("#T_GONGSIDAIMA").val("");	
			jQuery("#T_JIACELEIBIE").val("");
		}
		
		//添加
		function addE(){ 
			$.dialog({
		        title: '检测项目信息添加',
		        content: 'url:<%=request.getContextPath()%>/view/gwm_item_add.jsp',
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '800px',
		        height: 500,
		        close: function(){
			       gridSearchItemGrid();
			    }
			});
			gridSearchItemGrid();
 		}
 		
 		//删除
 		function deleteE(flag){
			var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
		    if (!ids) {
		    alert("请先选择记录!");  
		       return false;  
			}
			  
		    if(flag==1){
			      var biaozhunIds =[];
				  //删除标准
				  var allIds = ids.split(",");
				  for ( var i = 0; i < allIds.length; i++) {
					var id = allIds[i];
					var childGridIds = $("#gridTable_"+id+"_t").jqGrid('getGridParam', 'selarrrow') + "";
				    if(childGridIds!=''&&childGridIds!='undefined'){
					     biaozhunIds.push(childGridIds);
					}
				  }
				  if(biaozhunIds.join()==''){
				     alert("请选择对应的检测标准!");
				     return false;
				  }else{
				     ids = biaozhunIds.join();
				  }
			} 
			
			if(!confirm("是否确认删除 ？")){
			   return false;
			}
			 var params = {  
			    "flag":flag,
		        "ids": ids
		     };
			var actionUrl = "<%=request.getContextPath() %>/autoForms/item!deleteGwmItem.action";  
			$.ajax({  
				  url : actionUrl,  
			      type : "post", 
			      data : params,  
			      dataType : "json",  
			      cache : false,  
			      error : function(textStatus, errorThrown) {  
			          alert("系统ajax交互错误: " + textStatus.value);  
			      },  
			      success : function(data, textStatus) {
			      	if(data.result=='success'){
			      		alert("删除成功！");       
			      		gridSearchItemGrid();    
			      	}else{
			      		alert("删除失败！");
			      	}
			    }  
			});
		}
		//刷新检测项目列表
	   function gridSearchItemGrid(){
	        jQuery("#gridTable").jqGrid('setGridParam',
	              {
	                  url:'<%=request.getContextPath() %>/autoForms/item!queryGwmItemList.action'
	              }).trigger("reloadGrid", [{page:1}]); 
	   }
	   //修改
		function updateE(flag){
			var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			      return false; 
			}
			
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			var id = row.ID;//获取选中行的id属性.
			var biaozhunId='';
		    var  titleName = '检测项目信息修改';
		    var itemName = row.T_ITEMNAME;
		    var bumen = row.T_JIANCEBUMEN;
		    var leibie = row.T_JIACELEIBIE;
		    var danwei = row.T_JIANCEDANWEI;
		    var biaozun ='';
		    if(flag==1){
		        var biaozhunId = $("#gridTable_"+id+"_t").jqGrid('getGridParam', 'selarrrow') + "";
			    if(biaozhunId!=''&&biaozhunId!='undefined'){
			         if(biaozhunId.indexOf(",")!=-1){
			             alert("只能选择一条检测标准!");  
			             return false; 
			         }
			         var row1 = jQuery("#gridTable_"+id+"_t").jqGrid('getRowData',biaozhunId);//获取选中行
			         biaozun = row1.T_JIANCEBIAOZHUN;
				}else{
				    alert("请选择检测标准");
				    return false;
				}
		        titleName = '检测标准信息修改';
		    }
			$.dialog({
		        title: titleName,
		        content: 'url:'+ '<%=request.getContextPath() %>/item!updateGwmItemById.action?itemName='+encodeURIComponent(encodeURIComponent(itemName))+'&danwei='+danwei+'&biaozun='+encodeURIComponent(encodeURIComponent(biaozun))+'&flag='+flag+'&biaozhunId='+biaozhunId+'&bumen='+encodeURIComponent(encodeURIComponent(bumen))+'&leibie='+encodeURIComponent(encodeURIComponent(leibie))+'&temp='+Math.round(Math.random()*10000),
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '800px',
		        height:  550,
		        close: function(){
			       gridSearchItemGrid();
			    }
			});
		}
		
		//修改检测参数
		
		function updateCanshu(){
		    var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			      return false; 
			}
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			var itemname = encodeURIComponent(encodeURIComponent(row.T_ITEMNAME));
			var danwei =  row.T_JIANCEDANWEI;
			var leibie =  encodeURIComponent(encodeURIComponent(row.T_JIACELEIBIE));
			$.dialog({
		        title: '检测参数修改',
		        content: 'url:<%=request.getContextPath()%>/view/gwm_item_jiancecanshu.jsp?itemname='+itemname+'&danwei='+danwei+'&leibie='+leibie,
		        okVal: false,//确定按钮文字
		        cancelVal: false,//取消按钮文字
		        min: true, //是否显示最小化按钮
		        max: false,//是否显示最大化按钮
		        fixed: false,//开启静止定位
		        lock: true,//开启锁屏
		        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）
		        time: null,//设置对话框显示时间
		        resize: true,//是否允许用户调节尺寸
		        drag: true,//是否允许用户拖动位置
		        cache: false,//是否缓存iframe方式加载的窗口内容页
		        width: '800px',
		        height: 500,
		        close: function(){
			       gridSearchItemGrid();
			    }
			});
		}
	</script>	
	</head>
	<body>
	<form action="" method="post" id="form1">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
		   		<td>
			 		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			   		<tr>
			        	<td width="6%" height="35">检测项目：</td>
			        	<td width="11%"><input type="text" name="T_ITEMNAME" id="T_ITEMNAME" class="search_InputText" style="width:99%;"/></td>
			        	<td width="9%" height="35" align="right">检测单位：</td>
			        	<td width="11%"><input type="text" name="T_JIANCEDANWEI" id="T_JIANCEDANWEI"  class="search_InputText" style="width:99%;" /> </td>
			        	<td width="8%" height="35" align="right">检测地点：</td>
			        	<td width="11%"><input type="text" name="T_JIANCEDIDIAN" id="T_JIANCEDIDIAN"  class="search_InputText" style="width:99%;" /> </td>
			       	 	<td width="15%" align="center"><input type="button" name="button" id="button" value="查询" onclick="gridSearch()" class="search_Btn" />
			      			&nbsp;<input type="reset" name="button2" id="button2" value="清空" onclick="reset()" class="search_Btn" />
			      		</td>
			      	</tr>
			      	<tr>
			        	<td width="6%" height="35">检测部门：</td>
			        	<td width="11%"><input type="text" name="T_JIANCEBUMEN" id="T_JIANCEBUMEN" class="search_InputText" style="width:99%;"/></td>
			        	<td width="9%" height="35" align="right">检测类别：</td>
			        	<td width="11%"><input type="text" name="T_JIACELEIBIE" id="T_JIACELEIBIE"  class="search_InputText" style="width:99%;" /> </td>
			        	<td width="8%" height="35" align="right"></td>
			        	<td width="11%"></td>
			       	 	<td width="15%" align="center">
			      		</td>
			      	</tr>
			      	
			      </table>
			      <div id="panel" style="display:none;">
			      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			      	<tr>
			      	</tr>
			      	
			    </table>
			    </div>		    
		  		</td>
		 	  </tr>
		      <tr>
                <td align="right" height="9" class="sclinebotBg"></td>
	          </tr>
		      <tr>
			    <td width="92%" align="right"><div class="btnStatus" id="flip"></div></td>
			    <td width="8%">&nbsp;</td>
			  </tr>
			</table>
			<table style="width: 100%;" class="tableCont">
				<tr>
					<td height="25" valign="top">
			         	<input id="add"    type='button' value='添 加' onclick="addE()" class='button_b' />
						<input id="update" type='button' value='修改项目' onclick='updateE(0)' class='button_b' />
						<input id="update" type='button' value='修改标准' onclick='updateE(1)' class='button_b' />
						<input id="update" type='button' value='修改参数' onclick='updateCanshu()' class='button_b' />
						<input id="delete" type='button' value='删除项目' onclick='deleteE(0)' class='button_b' />
						<input id="delete" type='button' value='删除标准' onclick='deleteE(1)' class='button_b' />
				    </td>
				</tr>
				<tr>
					<td colspan="4" style="padding-top:8px;">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
		   </table>
	</form>
	</body>
</html>
